<template>
  <div class="pagination flex flex_center transition_0_3">
    
    <div class="base item pre transition_0_3 flex flex_center pointer"
    :class="{ disabled: currentPage === startPage }"
    @click="onChange(--currentPage)"
    >
      <span>上一页</span>
    </div>
    <template v-for="(item, index) in list">
      <div
        class="base item transition_0_3 flex flex_center pointer"
        :key="index"
        :class="{ active: item.active }"
        @click="onChange(item.page)"
      >
        <span>{{ item.page }}</span>
      </div>
    </template>
    <div class="base item next transition_0_3 flex flex_center pointer"
    :class="{ disabled: currentPage === endPage }"
    @click="onChange(++currentPage)"
    >
      <span>下一页</span>
    </div>
    <div class="base transition_0_3 flex flex_center pl_10 pr_10">
      {{`共 ${totalPage} 页`}}
    </div>
  </div>
</template>

<script>
export default {
  name: "pagination",
  props: {
    page: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    total: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      list: [],
      totalPage: 0,
      startPage: 1,
      endPage: 1,
      currentPage: 1,
    };
  },
  created() {
    this.getData(this.total, this.pageSize, this.page);
  },
  methods: {
    onChange(page) {
      this.currentPage = page;
      this.getData(this.total, this.pageSize, page);
      this.$emit("change", page);
    },
    getData(total, pageSize, page) {
      const item = this.U.pagination(total, pageSize, page);
      this.totalPage = item.totalPage;
      this.startPage = item.startPage;
      this.endPage = item.endPage;
      this.currentPage = item.currentPage;
      this.list = item.list;
      // console.log(item);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "./../style/theme.scss";
.pagination {
  .base{
    min-width: 50px;
    height: 40px;
    text-align: center;
    border: 2px solid $background;
    border-radius: 10px;
    margin: 5px;
    background-color: $background;
  }
  .item {
    width: 50px;
    &.active,&:hover {
      background-color: $blue-500;
      border: 2px solid $blue-500;
      color: $white;
      font-weight: bolder;
    }
  }
  .pre,.next{
    width: 80px;
  }
}
</style>